<template>
  <div>
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="选项">
        <el-select v-model="formInline.key" placeholder="选择要筛选的依据">
          <el-option label="名称" value="v_name"></el-option>
          <el-option label="编号" value="v_number"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="内容">
        <el-select v-model="formInline.value" placeholder="选择要筛选的依据">
          <el-option
              v-for="value in getValue"
              :label="value"
              :value="value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
        v-loading="loading"
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange">
      <el-table-column
          type="selection"
          width="55"
          >
      </el-table-column>
      <el-table-column
          prop="vname"
          label="名称"
          width="240">
      </el-table-column>
      <el-table-column
          prop="vnumber"
          label="编号"
          width="120">
      </el-table-column>
      <el-table-column
          prop="vstock"
          label="库存"
          width="120">
<!--        <el-tag type="success">标签二</el-tag>-->
      </el-table-column>
      <el-table-column
          prop="vmsg"
          label="描述"
          show-overflow-tooltip>
      </el-table-column>
      <el-table-column label="操作" fixed="right">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="success"
              @click="handleEdit(scope.$index, scope.row)">预约</el-button>
        </template>
      </el-table-column>
      <el-table-column
          prop="describe"
          label="详细信息"
          width="240"
          type="expand">
        <template slot-scope="props">
          <el-form label-position="left" class="demo-table-expand">
            <el-form-item label="名称:">
              <span>{{ props.row.vname }}</span>
            </el-form-item>
            <el-form-item label="编号:">
              <span>{{ props.row.vnumber }}</span>
            </el-form-item>
            <el-form-item label="库存:">
              <span>{{ props.row.vstock }}</span>
            </el-form-item>
            <el-form-item label="描述:">
              <span>{{ props.row.vmsg }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        style="margin-top: 20px"
        :page-size="pageSize"
        :pager-count="11"
        layout="prev, pager, next"
        :current-page.sync="currentPage"
        @current-change="page"
        :total="parseInt(total)">
    </el-pagination>
  </div>
</template>

<script>
import router from "@/router";

export default {
  name: "VaccineManager",
  data() {
    return {
      pageSize: 6,
      currentPage: 1,
      multipleSelection: [],
      tableData: null,
      total: "",
      loading:true,
      formInline: {
        key: '',
        value: '',
        page:0,
        pageSize:6
      },
      getValue:null
    }
  },
  methods: {
    page(currentPage){
      if (this.formInline.value===''){
        axios({
          url: `http://localhost:88/api/admin/sAdmin/pageList/${currentPage}/${this.pageSize}`,
          method: 'get'
        }).then((res) => {
          if (res.data.code === 0) {
            this.tableData = res.data.data.data
            this.total = res.data.data.total
          }
        })
      }else{
        this.formInline.page = this.currentPage
        axios({
          url:`http://localhost:88/api/admin/sAdmin/search`,
          method:'post',
          data:{
            key: this.formInline.key,
            value: this.formInline.value,
            page: this.formInline.page,
            pageSize: this.formInline.pageSize
          }
        }).then((res)=>{
          if(res.data.code === 0) {
            this.tableData = res.data.data.data
            this.total = res.data.data.total
          }
        })
      }
    },
    onSubmit() {
      axios({
        url:`http://localhost:88/api/admin/sAdmin/search`,
        method:'post',
        data:{
          key: this.formInline.key,
          value: this.formInline.value,
          page: this.formInline.page,
          pageSize: this.formInline.pageSize
        }
      }).then((res)=>{
        if(res.data.code === 0) {
          this.tableData = res.data.data.data
          this.total = res.data.data.total
        }
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleEdit(index, row) {
      this.$router.replace({name:'疫苗预约',params:{
          vname:row.vname,
          vmsg:row.vnumber,
          vid:row.vid,
          flag:'byRoute'
        }})
    },
  },
  watch:{
    "formInline.key"(newValue, oldValue){
      axios({
        url:'http://localhost:88/api/admin/sAdmin/searchByKey',
        method:'get',
        params:{
          newValue:newValue
        }
      }).then(res =>{
        console.log(res)
        this.getValue = res.data.result
      })
    }
  },
  mounted() {
    axios({
      url: `http://localhost:88/api/admin/sAdmin/pageList/1/${this.pageSize}`,
      method: 'get'
    }).then((res) => {
      if (res.data.code === 0) {
        this.tableData = res.data.data.data
        this.total = res.data.data.total
        this.loading=false
      }
    })
  }
}
</script>

<style scoped>

</style>
